import answer from '../model/answer.js';

export async function addAnswer(answerInfo) {
  return await answer.create(answerInfo);
}

export async function queryAnswerBySubordinate(subordinate) {
  return await answer.findAll({
    where: {
      subordinate_question: subordinate,
    },
  });
}

export async function queryAnswerByUser(user_id) {
  return await answer.findAll({
    where: {
      answer_creator: user_id,
    },
  });
}

export async function deleteAnswerBySubordinate(subordinate) {
  return await answer.destroy({
    where: {
      subordinate_question: subordinate,
    },
  });
}

export async function goodAnswerReputation(answer_id, value) {
  return await answer.increment(
    { good_reputation: value },
    {
      where: {
        answer_id,
      },
    },
  );
}
